using System.Collections.Generic;
using UnityEngine;

public class GameHelp
{

    /// <summary>
    /// 用户身上的物品列表
    /// </summary>
    public static List<PropItemTable> mPlayerPropList = new List<PropItemTable>();
    // public override void InitData() { }
    // public override void ClearData() { }
    public static Camera mCamera3D;
    //场景中的碰撞
    public static GameObject mFarmeBox;
    public static GameObject mFrameBoxGaizi;

    /// <summary>
    /// 游戏暂停
    /// </summary>
    public static bool GamePause = false;

    /// <summary>
    /// 游戏类型 1是消消 2是翻牌
    /// </summary>
    public static int GameType = 0;
    
    /// <summary>
    /// 是否可以进行射线检测
    /// </summary>
    public static bool CanRayCast = false;

    /// <summary>
    /// 桌面的桌子
    /// </summary>
    public static Transform Table;

    /// <summary>
    /// 当前关卡等级，也就是任务难度 1简单 2中等 以此类推
    /// </summary>
    public static int GameLevel = 1;

    /// <summary>
    /// 游戏持续时间是多久
    /// </summary>
    public static int GameTimer = 0;
    
    public static void OnInitRoom()
    {
        CanRayCast = true;
        if (GameType == 1)
        {
            // G1BackTimes = 0;
            G1GameEndSeeAdv = 0;
            GameTimer = 300;
            
            Table.transform.localPosition = new Vector3(0, 0, 1.5f);
        }
        else if (GameType == 2)
        {
            Table.transform.localPosition = Vector3.zero;
            GameTimer = 20*GameLevel;
            Table.transform.localPosition = new Vector3(0, 0, 0);
        }
    }
    
    
    
    
    //game1
    //有多少格子
    public static int[] Game1SendCardCountList = new int[] { 3, 3, 18, 23, 27, 31, 33, 40, 42, 45, 45, 45, 45 };//max 42
    //格子满了 游戏结束，提示看广告
    public static int G1GameEndSeeAdv = 0;

    
    //game2 int[] 0,1 棋盘大小  2可点击次数
    public static int[] GameShowCardRuleCountList = new int[] { 3, 3, 4, 7, 9, 10, 9, 10, 11, 10, 18 };//max 42



    //公共方法
    public static List<MJCS> OnResetMjPos(int mjcount)
    {
        MJCtrl.Instance().OnDesctroyCard();
        List<MJCS> mjlist = MJCtrl.Instance().OnGetNeedShowMjList(mjcount,true);
        int index = 0;
        int hang = 0;
        int hangnum = 0;
        int hangmax = 5;
        int liemax = 5;
        int qipanmax = hangmax * liemax;
        float hight = 0.5f;
        float startX = -1.8f;
        float stapx = 0.9f;
        float starty = 3f;
        float stapy = 1f;
        float scale = 1;
        
        if (mjcount >= 18)
        {
            hangmax = 6;
            liemax = 9;
            qipanmax = hangmax * liemax;
            stapx = 0.7f;
            starty = 3.5f;
            stapy = 0.8f;
            scale = 0.8f;
        }
        else if (mjcount >= 5)
        {
            hangmax = 6;
            liemax = 8;
            qipanmax = hangmax * liemax;
            stapx = 0.7f;
            starty = 3;
            stapy = 0.8f;
            scale = 0.8f;
        }
        else if (mjcount <= 3)
        {
            hangmax = 3;
            liemax = 3;
            qipanmax = hangmax * liemax;
            startX = -1.8f + 0.9f;
            stapx = 0.9f;
            starty = 2f;
            stapy = 1;
            scale = 1;
        }
        else if (mjcount <= 4)
        {
            hangmax = 6;
            liemax = 4;
            qipanmax = hangmax * liemax;
            startX = -1.8f;
            stapx = 0.7f;
            starty = 2f;
            stapy = 0.8f;
            scale = 0.8f;
        }

        //30的原因是因为那边写了 { 2, new[] { 10, 8 } } 传入是10扩大之后是30
        for (int i = 0; i < mjlist.Count; i++)
        {
            mjlist[i].OnLockRightBodyRotation(false);
            index = i%qipanmax;
            int gaodulv = i / qipanmax;
            if (i >= qipanmax)
            {
                hight = gaodulv * 0.4f + 0.3f;
            }
            float x = startX + index * stapx;
            float z = starty - (index / hangmax) * +stapy;
            if (hang == (int)(index / hangmax))
            {
                x = startX + hangnum * stapx;
                hangnum++;
            }
            else
            {
                hang = (int)(index / hangmax);
                hangnum = 0;
                x = startX + hangnum * stapx;
                hangnum++;
            }
                
            mjlist[i].OnSetLive();
            mjlist[i].OnSetSale(scale);
            mjlist[i].OnShowCardBe(x,z,hight);//GameType == 2
        }

        return mjlist;
    }

    //获取棋盘上的棋子每个可落脚点的位置
    public static List<Vector3> OnGetAllPos()
    {
        List<Vector3> qizipos = new List<Vector3>();
        int index = 0;
        int hang = 0;
        int hangnum = 0;
        int hangmax = 5;
        int liemax = 5;
        int qipanmax = hangmax * liemax;
        float hight = 0.5f;
        float startX = -1.8f;
        float stapx = 0.8f;
        float starty = 3f;
        float stapy = 1f;
            
        //30的原因是因为那边写了 { 2, new[] { 10, 8 } } 传入是10扩
        //大之后是30
        for (int i = 0; i < qipanmax*6; i++)
        {
            index = i%qipanmax;
            int gaodulv = i / qipanmax;
            if (i >= qipanmax)
            {
                hight = gaodulv * 0.4f+0.2f;
            }
            float x = -startX - index * stapx;
            float z = starty - (index / hangmax) * +stapy;
            if (hang == (int)(index / hangmax))
            {
                x = -startX - hangnum * stapx;
                hangnum++;
            }
            else
            {
                hang = (int)(index / hangmax);
                hangnum = 0;
                x = -startX - hangnum * stapx;
                hangnum++;
            }
            qizipos.Add(new Vector3(x,hight,z));
        }

        return qizipos;
    }

























    #region 删除或者添加用户身上的一个物品

    /// <summary>
    /// 删除用户身上的一个物品
    /// </summary>
    /// <param name="idlist"></param>
    public static void OnRemoveSelfPlayerPropItemById(List<PropItemEnum> idlist)
    {
        for (int i = 0; i < idlist.Count; i++)
        {
            for (int k = 0; k < mPlayerPropList.Count; k++)
            {
                if (mPlayerPropList[k].enumid == idlist[i])
                {
                    TaskManager.OnAddTaskNumByTaskType(TaskTypeEnum.useprop);
                    mPlayerPropList.RemoveAt(k);
                    break;
                }
            }
        }
        GameLocalInfo.OnSetSelfItemToLocal();
    }
    
    //添加物品到自己身上  如果是钱或者体力的话直接加上
    public static void OnAddSelfPlayerPropItem(PropItemTable item,bool setlocal = true)
    {
        if (item.enumid == PropItemEnum.jinbi)
        {
            GameLocalInfo.OnUpdatePlayerGold(item.count);
        }
        else if (item.enumid == PropItemEnum.tili)
        {
            GameLocalInfo.OnUpdatePlayerPower(item.count);
        }
        else
        {
            mPlayerPropList.Add(item);
            if (setlocal)
            {
                GameLocalInfo.OnSetSelfItemToLocal();
            }
        }
    }
    public static List<PropItemTable> OnGetSelfPlayerPropItemTable()
    {
        return mPlayerPropList;
    }

    public static void OnInitPlayerPropItemTable()
    {
        mPlayerPropList = new List<PropItemTable>();
    }

    #endregion
    
}
